from common.base_api import BaseApi
from common.wrapper import api_call


class UserApi(BaseApi):
    @api_call
    def sms_api(self, mobile: str, smsTemplate: str, channelCode: str, picSign, picCode):
        """

        :param mobile: 手机号，必须
        :param smsTemplate: 短信类型，必须
            * 用户注册短信  *    REGISTER,
            * 用户登陆     *    LOGIN,
            * 用户更换手机号 *   CHANGE_MOBILE,
            * 用户设置新手机号*  SET_NEW_MOBILE,
            * 用户重置密码   *   RESET_PASSWORD,
            * 重置支付密码      */     RESET_PAY_PASSWORD,/**    * 用户注册短信(无密码)   */ REGISTER_NO_PWD，
/**    * 用户登录即注册短信(无密码)   */  APP_REGISTER；
        :param channelCode:
        :param picSign:
        :param picCode:
        :return:
        """
        pass

    @api_call
    def wallet_api(self, token):
        """
        用户钱包余额
        :param token:
        :return:
        """
        api = self.conf_data['api']['user']['wallet']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'json': {}
        }
        response = self.send_http(data)
        return response

    @api_call
    def detail_api(self, token):
        """
        用户详细信息
        :param token:
        :return:
        """
        api = self.conf_data['api']['user']['detail']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'json': {}
        }
        response = self.send_http(data)
        return response

    @api_call
    def bind_bank_card_api(self, token, cardNo, bankAccountNature, **kwargs):
        """
         绑定银行卡
        :param token:
        :param cardNo: 银行卡号 string
        :param bankAccountNature: 对公/对私,ENT=对公,PER=对私 string
        :param cardNo: 开户行名称,对公必填 string
        :param cardNo: 开户行联行号,对公必填 string
        :return:
        """
        api = self.conf_data['api']['user']['bind_bank_card']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'post',
            'headers': headers,
            'json': {"cardNo": cardNo,
                     "bankAccountNature": bankAccountNature}
        }
        data["json"].update(kwargs)
        response = self.send_http(data)
        return response

    @api_call
    def bank_card_list_api(self, token):
        """
        用户绑定银行卡列表
        :param token: 用户的token
        :return:
        """
        api = self.conf_data['api']['user']['bank_card_list']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'json': {}
        }
        response = self.send_http(data)
        return response

    @api_call
    def change_bank_card_api(self, token, cardNo, bankAccountNature, payPassword, card_id, **kwargs):
        """
        更换银行卡
        :param cardNo:银行卡号
        :param card_id:查询用户已绑定的银行卡,要替换哪个银行卡就把那条记录ID传过来
        :param bankAccountNature: 对公或对私,ENT=对公,PER=对私
        :param payPassword:支付密码
        :param bankName:开户行名称,对公必输
        :param bankCode:开户行联行号,对公必输
        :return:
        """
        api = self.conf_data['api']['user']['change_bank_card']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api + card_id,
            'method': 'post',
            'headers': headers,
            'json': {"cardNo": cardNo,
                     "bankAccountNature": bankAccountNature,
                     "payPassword": payPassword}
        }
        data['json'].update(kwargs)
        response = self.send_http(data)
        return response

    @api_call
    def balance_bill_list_api(self, token, typeList):
        """
         余额账单明细
        :param token:
        :param typeList: 账单类型,收/支 收入账单=INCOME,支出账单=EXPENDITURE
        :return:
        """
        api = self.conf_data['api']['user']['balance_bill_list']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'params': {"typeList": typeList}
        }
        response = self.send_http(data)
        return response

    @api_call
    def nectar_bill_list_api(self, token, typeList):
        """
         花蜜账单明细
        :param token:
        :param typeList: 账单类型,收/支 收入账单=INCOME,支出账单=EXPENDITURE
        :return:
        """
        api = self.conf_data['api']['user']['nectar_bill_list']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'params': {"typeList": typeList}
        }
        response = self.send_http(data)
        return response

    @api_call
    def pollen_bill_list_api(self, token, typeList):
        """
         花粉账单明细
        :param token:
        :param typeList: 账单类型,收/支 收入账单=INCOME,支出账单=EXPENDITURE
        :return:
        """
        api = self.conf_data['api']['user']['pollen_bill_list']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'params': {"typeList": typeList}
        }
        response = self.send_http(data)
        return response

    @api_call
    def apply_withdraw_api(self, token, amount, bankCardId, payPassword, bankName, actualReceivedAmount, channelCode):
        """
        余额申请提现
        :param token: 用户的登录态  必须
        :param amount: 提现金额  number  必须
        :param bankCardId: 提现银行卡记录ID  integer  必须
        :param payPassword: 交易密码  string   必须
        :param bankName: 开户行名称   string   必须
        :param actualReceivedAmount: 实际到账金额=1- [amount* 个税百分比（20%）]  number  必须
        :param channelCode:  业务渠道code  全链峰就是05   string  必须
        :return:
        """
        api = self.conf_data['api']['user']['apply_withdraw']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'post',
            'headers': headers,
            'json': {"amount": amount, "bankCardId": bankCardId, "payPassword": payPassword, 'bankName': bankName,
                     "actualReceivedAmount": actualReceivedAmount, "channelCode": channelCode}
        }
        response = self.send_http(data)
        return response

    @api_call
    def withdraw_list_api(self, token):
        """
        余额申请提现列表
        :param token:
        :return:
        """
        api = self.conf_data['api']['user']['withdraw_list']
        headers = self.headers
        headers["Authorization"] = token
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': headers,
            'json': {}
        }
        response = self.send_http(data)
        return response

    @api_call
    def income_tax_api(self):
        """
        查询提现个税百分比
        :return:
        code:number
        message: string
        data:  object
        """
        api = self.conf_data['api']['user']['income_tax']
        data = {
            'url': self.host + api,
            'method': 'get',
            'headers': self.headers,
            'json': {}
        }
        response = self.send_http(data)
        return response
